package com.amigo.online.provider.video.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import com.amigo.online.common.core.mybatis.MyMapper;
import com.amigo.online.provider.video.model.entity.UserBalance;

@Mapper
@Component
public interface UserBalanceMapper extends MyMapper<UserBalance> {

    @Update("update user_balance_tbl set balance = balance - #{reduce},updated_time=#{updateTime} where user_id = #{user_id}")
    public int updateReduceBalance(@Param("user_id") Long user_id, @Param("reduce") Integer reduce, @Param("updateTime") Long updateTime);

    @Update("update user_balance_tbl set balance = balance - #{reduce},updated_time=#{updateTime} where user_id = (select user_id from video_promote_tbl where id = #{promote_id})")
    public int updateReduceBalanceByPromoteId(@Param("promote_id") Long promote_id, @Param("reduce") Integer reduce, @Param("updateTime") Long updateTime);

    @Select("select balance from user_balance_tbl where user_id = #{user_id}")
    public Integer getBalanceByUserId(Long user_id);

    @Update("update user_balance_tbl set balance = balance + #{increment},updated_time=#{updateTime} where user_id = #{user_id}")
    public int updateAddBalance(@Param("user_id") Long userId, @Param("increment") Integer increment, @Param("updateTime") Long updateTime);
}
